package cn.smbms.service.user;

import cn.smbms.dao.user.UserMapper;
import cn.smbms.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    //用户登录
    @Override
    public User login(String userCode) {
        User user = userMapper.getLoginUser(userCode);
        //匹配密码
        if(null != user){
            return user;
        }
        return null;
    }

    //根据条件查询用户列表
    @Override
    public List<User> getUserList(String queryUserName, int queryUserRole, int currentPageNo, int pageSize) {
        int beginIndex = (currentPageNo-1) * pageSize;
        return userMapper.getUserList(queryUserName, queryUserRole, beginIndex,pageSize);
    }

    //通过条件查询-用户表记录数
    @Override
    public int getUserCount(String queryUserName, int _queryUserRole) {
        return userMapper.getUserCount(queryUserName,_queryUserRole);

    }

    //增加用户信息
    @Override
    public boolean add(User user) {
        return userMapper.add(user)>0;
    }

    //根据userCode查询出User
    @Override
    public User selectUserCodeExist(String userCode) throws Exception {
        return userMapper.getLoginUser(userCode);
    }

    //修改用户信息
    @Override
    public boolean update(User user) {
        return userMapper.update(user) > 0;
    }

    //根据ID查找user
    @Override
    public User getUserById(Integer id) {
        return userMapper.getUserById(id);
    }

    @Override
    public boolean updatePwd(int id, String pwd) {
        return userMapper.updatePwd(id,pwd) > 0;
    }

}
